/*
 * Created on Sep 2, 2004
 */
package com.scalar.chiptrack.operations.process.dao.gp;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.scalar.chiptrack.commons.Constants;
import com.scalar.chiptrack.db.DataSource;

/**
 * @author Ravikanth
**/
public class GPKitMakingDAO
{
	public static void saveBoardKit( String partNumber, String vendorArr, String description, String partGenDesc )
	{
		Connection conn 	 = null;
		PreparedStatement pstmt = null;
		ResultSet rs 		 = null;
		boolean success = false;

		try
		{
			if( partNumber != null )
			{
				conn = DataSource.getConnection( Constants.DATASOURCE_TYPE_GREAT_PLAINS );
				
				pstmt = conn.prepareCall( "{ call sp_ct_prod_save_products( ?, ?, ?, ?, ?, ? ) }" );
				pstmt.setString( 1, partNumber );
				pstmt.setString( 2, Constants.LOCATION_TYPE_FINISHED_GOODS );
				pstmt.setString( 3, Constants.LOCATION_TYPE_FINISHED_GOODS );
				pstmt.setString( 4, vendorArr );
				pstmt.setString( 5, description );
				pstmt.setString( 6, partGenDesc );
				pstmt.execute();
			}
			success = true;
		}
		catch( Exception e)
		{
			e.printStackTrace();	
		}
		finally
		{
			if( conn != null )
			{
				if( success )
					try {  conn.commit();  }catch (SQLException e1) {  e1.printStackTrace();  }
				else
					try {  conn.rollback();  }catch (SQLException e1) {  e1.printStackTrace();  }
			}

			if(rs != null){
				try{ rs.close(); }catch(SQLException ignore){}
			}
			if(pstmt != null){
				try{ pstmt.close(); }catch(SQLException ignore){}
			}
			if( conn != null){
				try{conn.close(); }catch(SQLException ignore){}
			}
		}
	}
}
